<template>
	<view class="container">
		<view class="" v-show="isAuthorization">
			<view class="" style="display: inline-block;">
				<button @click="image" style="border-radius: 100%;background-color: #faebd7;width: 100px;height: 100px;"></button>
				<navigator url="login/login">
					<button type="default" style="width: 380px;" @click="login">登录</button>
				</navigator>
			</view>
		</view>

		<view class="" v-show="!isAuthorization">
				<button @click="img" style="border-radius: 100%;background-color: #faebd7;width: 80px;
				height: 80px;display: flex;flex-direction: column;align-items: center;justify-content: center;" >
					<image v-if="!wu"  :src="'http://localhost:8090'+logins.icon" style="width: 55px;height: 55px;">
						</image>
					</button>
			<uni-list>
				<uni-list-item clickable @click="update" title="修改密码"></uni-list-item>
				<uni-list-item title="电话" :rightText="logins.telephone"></uni-list-item>
			</uni-list>
			<button type="default" @click="out">退出登录</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {

				wu: false,
				logins: {
					
				},
				isAuthorization: true
			}
		},
		methods: {
			login() {
				this.isAuthorization = false
				
			},
			out() {
				this.isAuthorization = true
			},
			image(){
				uni.showToast({
					title: '请先登录！',
					icon: 'none'
				});
			}
			,
			update(){
				
					uni.showToast({
					title: '您的密码为:'+this.logins.password+'\n修改功能还未开发，很抱歉给您带来的不便',
					icon: 'none',
					duration:4000
				});
				
				
				
			},
			
			img() {
				uni.chooseImage({
					count: 1,
					success: (res) => {
						const FilePaths = res.tempFilePaths[0]
						const Files = res.tempFiles[0]
						
						uni.uploadFile({
							url: 'http://localhost:8090/foodapp/uploadheadicon',
							formData: {
								id: this.logins.id,

								file: Files,
								
							},
							filePath: FilePaths,
							name: "file",
							success: (res) => {
								let i = JSON.parse(res.data)
								this.logins.icon = i.headiconpath
								this.wu = false
								
							},
							fail: (err) => {
								console.log(err);
							},
							complete:(err)=> {
							}

						})
						
					}
				})
				

			}


			// onLoad: () => {

			// 	uni.onTabBarMidButtonTap(function(e){
			// 		console.log(e)

			// 	})
		},
		onShow() {

			this.logins = uni.getStorageSync('loginOne');

			if (this.logins.icon == null) {
				this.wu = true

			} else {
				this.wu = false
			}
			// console.log(this.logins);
		}

	}
</script>

<style>
	.container {
		padding: 20px;
		font-size: 14px;
		line-height: 24px;
	}

	* {
		margin: 0;
		padding: 0;
	}
</style>